#include<stdio.h>
#define N 100
#define NOTFOUND -1

typedef struct 
{
    char listname[25];
    int length;
    int data[N];
}list;

int binary_search(int a[],int n,int x)
{
    int left,right,mid;
    left=0,right=n-1;
    while(left<=right)
    {
        mid=(left+right)/2;
        if(x==a[mid])  return(mid);
        if(x<a[mid])   right=mid-1;   //准备查找前半段
        else           left=mid+1;    //准备查找后半段
    }
    return(NOTFOUND);
}

int main()
{
    int n,x,k;
    list second;
    second.length=0;
    printf("请输入查找模型数据大小：\n");
    scanf("%d",&n);
    printf("请输入查找模型数据样本：\n");
    for(int i=0;i<n;i++)
    {
        scanf("%d",&second.data[i]);
        second.length++;
    }
    printf("请输入需要查找的数据:");
    scanf("%d",&x);
    k=binary_search(second.data,second.length,x);
    if(k==NOTFOUND)  printf("没有找到数据\n");
    else             printf("找到数据,位置为%d",k);
}